/**
 * Created by gongxun on 17/1/13.
 */

var NnCardHelper = function(){
    var that = {};

    that.design = cc.size(130, 173);

    that.getCardSize = function(){
        var size;
        if (mo.gameHelper.developerVersion == "3.0"){
            size = cc.size(130, 173);
        }else if (mo.gameHelper.developerVersion == "2.0"){
            size = cc.size(151, 209);
        }
        return size;
    };

    that.getExistCardNum = function (cardNum) {
        if (cardNum >= 1 && cardNum <= 54){
            return true;
        }
        return false;
    };

    that.getRandomCard = function(size){
        var result = [];
        for (var i = 0; i < size; i++){
            result.push(parseInt(Math.random() * 54) + 1);
        }
        return result;
    };

    that.getInhandCardScale = function(seat){
        var result = 1;
        if (seat == 0){
            var expectedSize = that.design.width * 0.95 / that.getCardSize().width;
            result = expectedSize;
        }else{
            var expectedSize = that.design.width * 0.78 / that.getCardSize().width;
            result = expectedSize;
        }
        return result;
    };

    that.getInhandCardPos = function(seat, index){
        var pos = cc.p(0, 0);
        var center = cc.p(0, 0);
        var cardSize = that.getCardSize();
        var scale = 1;
        var addX = 45;
        if (seat == 0){
            center = cc.p(mo.gameSize.x / 2, 90);
            scale = 0.9;
            addX = 135;
        }else if (seat == 1){
            center = cc.p(mo.gameSize.x - 230, mo.gameSize.y - 310);
            scale = 0.78;
        }else if (seat == 2){
            center = cc.p(mo.gameSize.x - 295, mo.gameSize.y - 155);
            scale = 0.78;
        }else if (seat == 3){
            center = cc.p(295, mo.gameSize.y - 155);
            scale = 0.78;
        }else if (seat == 4){
            center = cc.p(230, mo.gameSize.y - 310);
            scale = 0.78;
        }

        pos.y = center.y;
        pos.x = (index - 2) * addX * scale + center.x;
        return pos;
    };

    that.getShowCardScale = function(seat){
        var expectedSize = that.design.width * 0.78 / that.getCardSize().width;
        return expectedSize;
    };

    that.getShowCardPos = function(seat, index, cardType){
        var result = cc.p(0, 0);
        if (seat == 0){
            var pos = cc.p(0, 0);
            var center = cc.p(mo.gameSize.x / 2, 100);
            var cardSize = that.getCardSize();
            var scale = 0.78;
            var addX = 45;

            pos.y = center.y;
            pos.x = (index - 2) * addX * scale + center.x;
            result = pos;
        }else{
            result = that.getInhandCardPos(seat, index);
        }

        //如果是开的有牛的 要留出间隔
        if (cardType > 0 && cardType <= 10){
            if (seat == 1 || seat == 2){
                if (index < 3){
                    result.x -= 20;
                }
            }else if (seat == 3 || seat == 4){
                if (index > 2){
                    result.x += 20;
                }
            }else{
                if (index < 3){
                    result.x -= 8;
                }else{
                    result.x += 12;
                }
            }
        }

        return result;
    };

    //返回表情序列帧
    that.getFaceFrames = function (index) {
        var spriteFrames = [];
        for (var i = 0; i <= 60; i++){
            var frame = cc.spriteFrameCache.getSpriteFrame("emoji_" + index + "_" + i + ".png");
            if (frame == null){
                break;
            }
            spriteFrames.push(frame);
        }
        return spriteFrames;
    };

    return that;
};

mo.nnCardHelper = new NnCardHelper();